#include <bits/stdc++.h>
using namespace std;
const int maxn = 300+5;
const int INF = 1<<30;
typedef long long ll ;
typedef pair<ll, ll> pll ;
int G[maxn][maxn];
int d[maxn<<1];
ll dp[maxn][maxn];
//bool vis[maxn][maxn];

int N, M, K;
int des;

pll DP(int x, int o){
    ll &ans = dp[x][o];
    if(dp[x][o]>-1)
        return {ans, o};
    if(x == des)
        return {0, o};
    ans = INF;



    for (int y = 1; y <= N; ++y) if(y!=x && G[x][y]){
            ans = min(ans, DP(y, o).first + G[x][y]);
        }
    if(x != o){
        ans = min(ans, DP(o, x).first);
        ans = min(ans, DP(o, o).first);
    }

    dp[x][o] = ans;
    return {ans, o};
}
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    cin >> N >> M >> K;
    for (int i = 0; i < M; ++i) {
        int a, b, w;
        cin >> a >> b >> w;
        if(!G[a][b] || G[a][b] < w)
            G[a][b] = G[b][a] = w;
    }
    for (int i = 0; i < 2*K; ++i) {
        cin >> d[i];
    }
    int s = 1, o = 1;
    ll ans = 0;
    for (int i = 0; i < 2 * K; ++i) {
        des = d[i];
        memset(dp, -1, sizeof(dp));
//        memset(vis, 0, sizeof(vis));
        pll tmp = DP(s, o);
        ans += tmp.first;
        o = tmp.second;
        s = des;
    }
    cout << ans;
    return 0;
}